package com.zerui.manager.icc.dto;

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * 订阅信息
 */
@Getter
@Setter
public class SubscribeVO {

    // 监听组
    private List<SubscribeMonitorVO> monitors = new ArrayList<>();

    // 订阅者信息
    private SubSystemVO subsystem;

    // 当前类构建器
    public static Builder builder() {
        return new Builder();
    }

    public static class Builder {

        // 订阅者信息
        private SubSystemVO subsystem;
        // 监听组
        private List<SubscribeMonitorVO> monitors = new ArrayList<>();

        // 主要分类 alarm
        public Builder magic(String magic) {
            this.subsystem = new SubSystemVO();
            this.subsystem.setName(magic);
            this.subsystem.setMagic(magic);
            return this;
        }

        public Builder monitor(String monitor, List<SubscribeEventVO> events) {
            SubscribeMonitorVO monitorVO = new SubscribeMonitorVO();
            monitorVO.setMonitor(monitor);
            monitorVO.setMonitorType("url");
            monitorVO.setEvents(events);
            this.monitors.add(monitorVO);
            return this;
        }

        public SubscribeVO build() {
            return new SubscribeVO(this);
        }
    }

    public SubscribeVO() {
        super();
    }

    public SubscribeVO(Builder builder) {
        this.subsystem = builder.subsystem;
        this.monitors = builder.monitors;
    }

    // 子系统信息
    @Getter
    @Setter
    public static class SubSystemVO {

        // 系统类型,0代表子系统 固定值：0
        private Integer subsystemType = 0;

        // 订阅者名称,唯一,建议与magic一样
        private String name;

        // 订阅者ip端口,子系统填ip_port， ip、port为字段monitor中的ip与端口
        private String magic;
    }

    // 监听组
    @Getter
    @Setter
    public static class SubscribeMonitorVO {

        // 监听地址url地址
        private String monitor;

        // 监听类型,固定值为：url
        private String monitorType = "url";

        // 事件
        private List<SubscribeEventVO> events;
    }
}
